package com.gzlg.hospital.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gzlg.hospital.dao.UserDao;
import com.gzlg.hospital.pojo.User;
import com.gzlg.hospital.pojo.query.UserQuery;
import com.gzlg.hospital.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public List<User> listUser() {
        return userDao.listUser();
    }
    @Override
    public PageInfo<User> listUserByName(UserQuery userQuery) {
        PageHelper.startPage(userQuery.getPageNum(),userQuery.getPageSize());
        return new PageInfo<User>(userDao.listUserByName(userQuery));
    }

    @Override
    public boolean deleteUserById(Integer id) {
        int result = userDao.deleteUserById(id);
        return result > 0;
    }

    @Override
    public User getUserById(Integer id) {
        return userDao.getUserById(id);
    }

    @Override
    public boolean updateUser(User user) {
        int result = userDao.updateUser(user);
        return result > 0;
    }

    @Override
    public boolean addUser(User user) {
        int result =userDao.addUser(user);
        return result > 0;
    }
}